package com.anjubao.parking.municipal.payment.controller;


import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.common.utils.BeanUtils;
import com.anjubao.parking.municipal.payment.form.WxPayJsapiForm;
import com.anjubao.parking.municipal.payment.dto.PayResponseDto;
import com.anjubao.parking.municipal.payment.feign.ParkingTradePaymentRest;
import com.anjubao.parking.municipal.payment.service.WeiXinPayService;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 支付api
 *
 * @author zhuchunfeng
 */
@RestController
@RequestMapping("/parking-trade-payments")
@Slf4j
@Api(value = "车场支付订单相关接口",tags = {"支付相关接口"})
public class ParkingTradePaymentController implements ParkingTradePaymentRest {

    @Resource
    private WeiXinPayService weiXinPayService;

    /**
     * 微信公众号 支付
     * @param payRequestForm 支付信息
     * @return 请求结果
     */
    @Override
    @PostMapping("/wx/pay-order-mp")
    @ApiOperation("微信公众号 支付")
    public ApiResult<PayResponseDto> wxPayJsapi(@RequestBody WxPayJsapiForm payRequestForm) {
        WxPayMpOrderResult wxPayMpOrderResult = weiXinPayService.wxPayJSAPI(payRequestForm);
        PayResponseDto transform = BeanUtils.transform(PayResponseDto.class, wxPayMpOrderResult);
        return ApiResult.success(transform);
    }

    /**
     * 微信 pc 支付
     * @param payRequestForm 支付信息
     * @return mwebUrl 支付跳转链接
     */
    @PostMapping("/wx/pay-order-pc")
    public ApiResult<PayResponseDto> wxPayNative(@RequestBody WxPayJsapiForm payRequestForm) {
        WxPayNativeOrderResult result = weiXinPayService.wxPayNative(payRequestForm);
        PayResponseDto transform = BeanUtils.transform(PayResponseDto.class, result);
        return ApiResult.success(transform);
    }
}
